package com.shiro.receiver.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shiro.receiver.entity.Payload;
import com.shiro.receiver.framework.constant.BotOperationType;
import com.shiro.receiver.manager.CallbackManager;

@Slf4j
@RestController
@RequestMapping
@RequiredArgsConstructor
public class CallbackController {

    private final CallbackManager callbackManager;

    @PostMapping("/callback")
    public Payload<Void> callback(@RequestBody Payload<JSONObject> payload) {
        callbackManager.handleCallbackAsync(payload);
        return new Payload<>(payload.getId(), BotOperationType.HTTP_CALLBACK_ACK.getValue(), payload.getSequence(), payload.getEventType());
    }

}
